z = input()
f = 0
if len(z) == 4:
    for i in range(0,4):
        for y in range(i+1,5):
            t = int(z[i:y])
            g = 0
            for x in range(1,t+1):
                if t % x == 0:
                    g = g + 1
            if g == 2:
                f = max(f,t)
print(f)